package com.example.commons.constant;

/**
 * 启动类配置文件
 * @author whx
 * @date 2022/4/12
 */
public interface LauncherConstant {

    String DEV_CODE = "dev";
    String PROD_CODE = "prod";
    String TEST_CODE = "test";

    String NACOS_DEV_ADDR = "localhost:8848";
    String NACOS_PROD_ADDR = "localhost:8848";
    String NACOS_TEST_ADDR = "localhost:8848";
    String NACOS_USERNAME = "nacos";
    String NACOS_PASSWORD = "nacos";
    String CONFIG_FORMAT_DEFAULT = "yaml";
    String SHARE_DATA_ID_DEFAULT = "blade";

    /**
     * 动态获取nacos地址
     *
     * @param profile 环境变量
     * @return addr
     */
    static String nacosAddr(String profile) {
        switch (profile) {
            case (PROD_CODE):
                return NACOS_PROD_ADDR;
            case (TEST_CODE):
                return NACOS_TEST_ADDR;
            default:
                return NACOS_DEV_ADDR;
        }
    }

    static String dataId(String appName){
        return appName + "." + CONFIG_FORMAT_DEFAULT;
    }

    static String dataId(String appName,String profile){
        return dataId(appName + "-" + profile);
    }

    static String dataId(String appName,String profile,String format){
        return appName + "-" + profile + "." + format;
    }

    static String sharedDataId(){
        return SHARE_DATA_ID_DEFAULT+"."+CONFIG_FORMAT_DEFAULT;
    }

    static String sharedDataId(String profile){
        return SHARE_DATA_ID_DEFAULT + "-" + profile + "." + CONFIG_FORMAT_DEFAULT;
    }
}
